<template>
  <div>
    <div id="login2">
      <div class="my-login-box">
        <form>
          <div class="user-box">
            <input type="text" name="" required="" v-model="userId" />
            <label>账号</label>
          </div>
          <div class="user-box">
            <input
              type="password"
              name=""
              required=""
              v-model="password"
              show-password
            />
            <label>密码</label>
          </div>
          <el-row>
            <el-col :span="18"
              ><div class="grid-content bg-purple"></div
            ></el-col>
            <el-col :span="6">
              <div class="grid-content bg-purple">
                <router-link to="/Forgetpwd">忘记密码?</router-link>
              </div>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="7"
              ><div class="grid-content bg-purple"></div
            ></el-col>
            <el-col :span="11"
              ><div class="grid-content bg-purple-dark">
                <a
                  href="#"
                  class="a1"
                  @click.prevent="login"
                  :plain="true"
                  @click="num++"
                >
                  <span></span>
                  <span></span>
                  <span></span>
                  <span></span>
                  <h2>登录</h2>
                </a>
              </div></el-col
            >
            <el-col :span="6"
              ><div class="grid-content bg-purple"></div
            ></el-col>
          </el-row>
          <!-- </a> -->
        </form>
        <div>
          <el-row>
            <el-col :span="24">
              <div class="grid-content bg-purple">
                <router-link to="/Register">还没有账号?免费注册</router-link>
              </div></el-col
            >
          </el-row>
          <el-row>
            <el-col :span="24"
              ><div class="grid-content bg-purple mytext ">
                <el-checkbox v-model="checked" @change="checkeds"></el-checkbox
                >我已阅读并同意<a href="#">《用户协议》</a><a href="#">《隐私政策》</a>
                ，并授权使用该账号信息（如昵称、头像、收货地址）进行统一管理
              </div></el-col
            >
          </el-row>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "Lpassword",
  data() {
    return {
      //账号
      userId: "",
      //密码
      password: "",
      checked: true,
      num: 0,
      userName: "",
    };
  },
  methods: {
    checkeds() {
      this.checked = !this.checked;
    },
     open6() {
      this.$message({
        message: "密码错了！",
        type: "warning",
      });
    },
    open3() {
      this.$message("请先去注册！");
    },
    open2() {
      this.$message({
        message: "欢迎你,登录成功！" + this.userName,
        type: "success",
      });
    },
    open4() {
      this.$message({
        message: "错了哦,账号或密码错误！",
        type: "warning",
      });
    },
    open1() {
      this.$message.error("请同意用户协议！");
    },
    login() {
      this.$axios
        .post("/api/users/login", {
          userId: this.userId,
          password: this.password,
        })
        .then((res) => {
          if (res.data.code == 500) {
           this.open6()
          }
          this.userName = res.data.datas[0].niceName;

          if (res.data.data != undefined) {
            if (this.checked == true) {
              //是否传参
              //  this.$router.push({name:'/',params:{userId:this.userId}})
              this.$router.push("/");
              this.open2();
              // 登录成功,将id添加到本地存储;
              //保存token令牌保存在本地
              localStorage.setItem("myToken", res.data.data);
              localStorage.setItem("Have", JSON.stringify(res.data.datas));
              this.$store.state.userInfo = res.data.datas[0];
              this.$store.state.userInfo.portrit =
                `http://localhost:3000/upload/` + res.data.datas[0].portrit;
              // console.log('头像',this.$store.state.userInfo.portrit)
            } else {
              this.checked = true;
              this.open1();
            }
          } else {
            if (this.num < 6) {
              this.open4();
            } else {
              this.open3();
            }
          }
        });
    },
  },
};
</script>

<style scoped>

#login2 {
  font-family: "楷体";
  display: inline-block;
  position: absolute;
  top: 50px;
  width: 500px;
  height: 450px;
  margin-top: 25px;
}

.grid-content {
  min-height: 36px;
  line-height: 36px;
}
.row-bg {
  background-color: #f9fafc;
}
html {
  height: 100%;
}
body {
  margin: 0;
  padding: 0;
  font-family: sans-serif;
  background: linear-gradient(#141e30, #243b55);
}
.my-login-box {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 400px;
  padding: 40px;
  transform: translate(-50%, -50%);
  background: rgba(0, 0, 0, 0.3);
  box-sizing: border-box;
  box-shadow: 0 15px 25px rgba(0, 0, 0, 0.6);
  border-radius: 10px;
}
.my-login-box h2 {
  margin: 0 0 30px;
  padding: 0;
  color: #fff;
  text-align: center;
}
.my-login-box .user-box {
  position: relative;
}
.my-login-box .user-box input {
  width: 100%;
  padding: 10px 0;
  font-size: 16px;
  color: #fff;
  margin-bottom: 30px;
  border: none;
  border-bottom: 1px solid #fff;
  outline: none;
  background: transparent;
}
.my-login-box .user-box label {
  position: absolute;
  top: 0;
  left: 0;
  padding: 10px 0;
  font-size: 16px;
  color: #fff;
  pointer-events: none;
  transition: 0.5s;
}
.my-login-box .user-box input:focus ~ label,
.my-login-box .user-box input:valid ~ label {
  top: -30px;
  left: 0;
  color: #03e9f4;
  font-size: 12px;
}
h2 {
  width: 100px;
  height: 10px;
}
.my-login-box form .a1 {
  position: relative;
  display: inline-block;
  padding: 10px 20px;
  color: #03e9f4;
  font-size: 16px;
  text-decoration: none;
  text-transform: uppercase;
  overflow: hidden;
  transition: 0.5s;
  margin-top: 10px;
  letter-spacing: 4px;
}
.my-login-box .a1:hover {
  background: #03e9f4;
  color: #fff;
  border-radius: 5px;
  box-shadow: 0 0 5px #48e3eb, 0 0 25px #72edf3, 0 0 50px #03e9f4,
    0 0 100px #03e9f4;
}
.my-login-box a span {
  position: absolute;
  display: block;
}
.my-login-box a span:nth-child(1) {
  top: 0;
  left: -100%;
  width: 100%;
  height: 2px;
  background: linear-gradient(90deg, transparent, #03e9f4);
  animation: btn-anim1 1s linear infinite;
}
@keyframes btn-anim1 {
  0% {
    left: -100%;
  }
  50%,
  100% {
    left: 100%;
  }
}
.my-login-box a span:nth-child(2) {
  top: -100%;
  right: 0;
  width: 2px;
  height: 100%;
  background: linear-gradient(180deg, transparent, #03e9f4);
  animation: btn-anim2 1s linear infinite;
  animation-delay: 0.25s;
}
@keyframes btn-anim2 {
  0% {
    top: -100%;
  }
  50%,
  100% {
    top: 100%;
  }
}
.my-login-box a span:nth-child(3) {
  bottom: 0;
  right: -100%;
  width: 100%;
  height: 2px;
  background: linear-gradient(270deg, transparent, #03e9f4);
  animation: btn-anim3 1s linear infinite;
  animation-delay: 0.5s;
}
@keyframes btn-anim3 {
  0% {
    right: -100%;
  }
  50%,
  100% {
    right: 100%;
  }
}

.my-login-box a span:nth-child(4) {
  bottom: -100%;
  left: 0;
  width: 2px;
  height: 100%;
  background: linear-gradient(360deg, transparent, #03e9f4);
  animation: btn-anim4 1s linear infinite;
  animation-delay: 0.75s;
}
@keyframes btn-anim4 {
  0% {
    bottom: -100%;
  }
  50%,
  100% {
    bottom: 100%;
  }
}
/* 我已阅读字体样式 */
.mytext {
  line-height: 26px;
  font-size: 18px;
  font-weight: 550;
  color:rgb(44, 44, 44);
}
</style>
